<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function calculateDepreciation(){
            var pric = parseFloat(document.getElementById("txtPric").value);
            var rate = parseFloat(document.getElementById("txtRate").value);
            var year = parseFloat(document.getElementById("txtYear").value);
            var result = document.getElementById("txtResult");
            for (var i = 1; i <= year; i++) {
                result.innerHTML += i + "    " + pric* Math.pow((1-rate),i) + "     " + toDecimal2(pric* Math.pow((1-rate),i)) +"\n";
            }
        }

        //保留两位小数
        function toDecimal2(x) {
            var f = Math.round(x*100)/100;
            var s = f.toString();
            var rs = s.indexOf('.');
            //没有小数位
            if (rs == -1) {
                s += '.00';
                return s;
            }
            //一个小数位
            if (rs == s.length-2){
                s+="0";
                return s;
            }
            return s.substring(0,rs+3);
        }

    </script>
</head>
<body>
录入资产采购时的价值：<input id="txtPric" type="text"><br/>
录入折旧率：<input id="txtRate" type="text"/><br/>
录入计算年限：<input id="txtYear" type="text"/><br/>
<input type="button" value="计算" onclick="calculateDepreciation()"/><br/>
<textarea id="txtResult" cols="50" rows="5">

</textarea>
</body>
</html>